﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using Logistics_Service.DTO;

namespace Logistics_Service.DAO
{
    public class LichVanChuyenDAO
    {
        public LichVanChuyenDTO[] DanhSachLichVanChuyen()
        {
            LichVanChuyenDTO[] arr;
            string query = string.Format("select * from LichVanChuyen");
            DataProvider provider = new DataProvider();
            DataTable dt = provider.ExecuteQuery(query);
            int n = dt.Rows.Count;
            arr = new LichVanChuyenDTO[n];
            for (int i = 0; i < n; i++)
            {
                object lvc = GetDataFromDataRow(dt, i);
                arr[i] = (LichVanChuyenDTO)lvc;
            }
            return arr;
        }
        protected object GetDataFromDataRow(DataTable dt, int i)
        {
            LichVanChuyenDTO lvc = new LichVanChuyenDTO();
            lvc.Ma = dt.Rows[i]["Ma"].ToString();
            lvc.MaTuyen = dt.Rows[i]["Ten"].ToString();
            lvc.MaXe = dt.Rows[i]["MaXe"].ToString();
            lvc.NgayGio = dt.Rows[i]["NgayGio"].ToString();            
            lvc.DaXoa = bool.Parse(dt.Rows[i]["DaXoa"].ToString());
            return (object)lvc;
        }  
    }
}